package cn.ycl.system.other.study.designMode;

/**
 * @author YuanChangLiang
 * @description 使用双层校验锁，创建单例
 * @date created in 13:55 2021/7/1
 */


public class Food2 {
    /**
     * 先通过private构造方法，堵死new一个实例的可能
     */
    private Food2(){}

    public static volatile Food2 food2 = null;
    public static Food2 getInstance(){
        if(food2 == null){
            synchronized (Food2.class){
                if (food2 == null){
                    food2 = new Food2();
                }
            }
        }
        return food2;
    }
}
